package com.ymatou.iapi.productquery.testcase.old20210113;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productquery.parameter.GetProductListBySellerIdBean;
import com.ymatou.iapi.productquery.parameter.ProductInListDto;
import com.ymatou.iapi.productquery.service.GetProductListBySellerIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.utils.AgentUsers;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Ignore
public class Ts_GetProductListBySellerId {
	private static GetProductListBySellerIdCall getProductListBySellerIdCall = new GetProductListBySellerIdCall();
	private static GetProductListBySellerIdBean getProductListBySellerIdBean = new GetProductListBySellerIdBean();

	//渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	//渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";

	//vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	//vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	//vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播小铺买手主页商品列表");
		try {
			GodfreightmgrService.deleteBySellerId(rootUserId);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getProductListBySellerIdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_001() {
		Logger.start(true,"查询渠道商品");
		try{
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			getProductListBySellerIdBean.setSellerId(vipRootUserId);
			getProductListBySellerIdBean.setProductType(3);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(10);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			Thread.sleep(2000);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			ArrayList<ProductInListDto> productList = getProductListBySellerIdCall.getProductList();
			List<String> productIds = productList.stream().map(x -> x.getProductId()).collect(Collectors.toList());
			Logger.verifyEquals(false,productIds.toString().contains(productId),"验证买家端店铺首页中无该商品");
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_00101() {
		Logger.start(true,"查询神器渠道商品，买家端店铺首页中不可见");
		try{
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,false);
			addAgentProductBean.setInvisible(false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			getProductListBySellerIdBean.setSellerId(vipRootUserId);
			getProductListBySellerIdBean.setProductType(3);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(10);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			Thread.sleep(2000);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			ArrayList<ProductInListDto> productList = getProductListBySellerIdCall.getProductList();
			List<String> productIds = productList.stream().map(x -> x.getProductId()).collect(Collectors.toList());
			Logger.verifyEquals(true,productIds.toString().contains(productId),"验证买家端店铺首页中有该商品");
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_002() {
		Logger.start(true,"查询代理商商品");
		try{
			getProductListBySellerIdBean.setSellerId(agentUserId1);
			getProductListBySellerIdBean.setProductType(3);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(10);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_003() {
		Logger.start(true,"查询vip代理商商品");
		try{
			getProductListBySellerIdBean.setSellerId(vipAgentUserId1);
			getProductListBySellerIdBean.setProductType(3);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(10);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_004() {
		Logger.start(true,"全球优选");
		try{
			int sellerId = 20336378;
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			Thread.sleep(2000);
			getProductListBySellerIdBean.setSellerId(sellerId);
			getProductListBySellerIdBean.setProductType(2);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(10);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			ArrayList<ProductInListDto> productList = getProductListBySellerIdCall.getProductList();
			List<String> prodIds = productList.stream().map(p -> p.getProductId()).collect(Collectors.toList());
			Logger.verifyEquals(true,prodIds.contains(productId),"验证返回结果");
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_005() {
		Logger.start(true,"查询自采商品");
		try{
			int sellerId = 20336378;
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			Thread.sleep(2000);
			getProductListBySellerIdBean.setSellerId(sellerId);
			getProductListBySellerIdBean.setProductType(2);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(10);
			getProductListBySellerIdBean.setAgentProductType(1);
			
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			ArrayList<ProductInListDto> productList = getProductListBySellerIdCall.getProductList();
			List<String> prodIds = productList.stream().map(p -> p.getProductId()).collect(Collectors.toList());
			Logger.verifyEquals(true,prodIds.contains(productId),"验证返回结果");
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_006() {
		Logger.start(true,"查询代理商品");
		try{
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			
			Thread.sleep(2000);
			getProductListBySellerIdBean.setSellerId(vipAgentUserId1);
			getProductListBySellerIdBean.setProductType(3);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(49);
			getProductListBySellerIdBean.setAgentProductType(2);
			
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			ArrayList<ProductInListDto> productList = getProductListBySellerIdCall.getProductList();
			List<String> prodIds = productList.stream().map(p -> p.getProductId()).collect(Collectors.toList());
			Logger.verifyEquals(true,prodIds.contains(agentProductId),"验证返回结果");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductListBySellerId_007() {
		Logger.start(true,"验证记录");
		try{
			getProductListBySellerIdBean.setSellerId(rootUserId);
			getProductListBySellerIdBean.setProductType(3);
			getProductListBySellerIdBean.setPageIndex(1);
			getProductListBySellerIdBean.setPageSize(49);
			getProductListBySellerIdBean.setAgentProductType(2);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			int agent = getProductListBySellerIdCall.getJsonObject().getAsJsonObject("Data").get("TotalCount").getAsInt();
			
			getProductListBySellerIdBean.setAgentProductType(1);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			int zicai = getProductListBySellerIdCall.getJsonObject().getAsJsonObject("Data").get("TotalCount").getAsInt();
			
			
			getProductListBySellerIdBean.setAgentProductType(0);
			getProductListBySellerIdCall.setData(getProductListBySellerIdBean);
			getProductListBySellerIdCall.callService();
			Logger.verifyEquals("200",getProductListBySellerIdCall.getString("Code"),"验证code");
			int zong = getProductListBySellerIdCall.getJsonObject().getAsJsonObject("Data").get("TotalCount").getAsInt();
			
			Logger.comment("自采商品数目"+zicai);
			Logger.comment("代理商品数目"+agent);
			Logger.comment("总共商品数目"+zong);
			
			Logger.verifyEquals(zong, zicai+agent, "验证数据查询");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

}
